package com.louis.iread.bean;

import android.content.Context;
import android.content.Intent;
import android.databinding.BindingAdapter;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.louis.iread.R;
import com.louis.iread.ui.NovelInfoActivity;
import com.louis.iread.utils.ConstValue;

import java.io.Serializable;

/**
 * Created by louis on 18-2-26.
 */

public class NovelPageItem implements Serializable{
    String novelName;  //小说名
    String cover;   //封面url
    String author;     //作者

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    String type; //小说类型

    public String getNovelUrl() {
        return novelUrl;
    }

    public void setNovelUrl(String novelUrl) {
        this.novelUrl = novelUrl;
    }

    String novelUrl; //小说主页

    public String getContentsUrl() {
        return contentsUrl;
    }

    public void setContentsUrl(String contentsUrl) {
        this.contentsUrl = contentsUrl;
    }

    String contentsUrl; //小说目录

    public String getNovelId() {
        return novelId;
    }

    public void setNovelId(String novelId) {
        this.novelId = novelId;
    }

    String novelId;         //小说id
    String latestArticle;  //最新章节

    public String getNovelName() {
        return novelName;
    }

    public void setNovelName(String novelName) {
        this.novelName = novelName;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String coverUrl) {
        this.cover = coverUrl;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getLatestArticle() {
        return latestArticle;
    }

    public void setLatestArticle(String latestArticle) {
        this.latestArticle = latestArticle;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    String updateTime; //更新时间

    public void onClick(View view) {
        Context context = view.getContext();
        Intent intent = new Intent(context, NovelInfoActivity.class);

        intent.putExtra(ConstValue.CLASS_PAGE_ITEM, this);

        context.startActivity(intent);
    }

    @BindingAdapter("cover")
    public static void loadInternetImage(ImageView iv, String coverUrl) {
        Glide.with(iv.getContext())
                .load(coverUrl)
                .apply(new RequestOptions().placeholder(R.drawable.nocover).error(R.drawable.nocover))
                .into(iv);
    }
}
